package chapter26;

import java.util.Arrays;
import java.util.List;
import java.util.Map;
import java.util.TreeMap;
import java.util.stream.Collectors;
import java.util.stream.Stream;

/**
 * @author lzy
 * @version v1.0
 * Create DateTime: 2019/2/28 17:12
 */
public class CollectorTest {
    public static void main(String[] args) {
        List<Student> students = Arrays.asList(new Student[]{
                new Student("zhangsan", 87.2),
                new Student("li", 87.2),
                new Student("wangwu", 97.4)});

        Map<String, Double> nameScoreMap = students.stream().collect(Collectors.toMap
                (Student::getName, Student::getScore));
        System.out.println(nameScoreMap.toString());

        TreeMap<String, Double> stringDoubleTreeMap = students.stream().collect(Collectors.toMap(Student::getName, Student::getScore, (old, duplicate) -> old, TreeMap::new));
        System.out.println(stringDoubleTreeMap);

        String result = Stream.of("abc", "laoma", "hello").collect(Collectors.joining(",", "[", "]"));
        System.out.println(result);
    }
}
